package com.jml.enCache和map实现单个jvm缓存.controller;


import com.jml.enCache和map实现单个jvm缓存.cache.MapCache;
import com.jml.enCache和map实现单个jvm缓存.entity.Users;
import com.jml.enCache和map实现单个jvm缓存.service.UserService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class CacheController {

	@Autowired
	private UserService userService;
	@Autowired
	private CacheManager cacheManager;
	//清除缓存
	@RequestMapping("/encacheRemove")
	public void encacheRemove() {
		cacheManager.getCache("userCache").clear();
	}
	@RequestMapping("/encacheGet")
	public String encacheGet (String key){
		List<Users> user = userService.getUser(1L);
		return user.get(0).getAge()+user.get(0).getName();
	}


	@Autowired
	private MapCache<String,Object> mapCache;

	@RequestMapping("/get")
	public String get (String key){
		return (String)mapCache.get(key);
	}

	@RequestMapping("/put")
	public String put (String key,String value){
		mapCache.put(key,value);
		return "put success";
	}
	@RequestMapping("/remove")
	public String remove (String key){
		mapCache.remove(key);
		return "remove success";
	}
}
